package mark.tom.friend.base.application;

import android.app.Application;
import android.support.annotation.CallSuper;

import com.alibaba.android.arouter.launcher.ARouter;
import com.facebook.stetho.Stetho;
import com.frogermcs.androiddevmetrics.AndroidDevMetrics;
import com.squareup.leakcanary.LeakCanary;

import timber.log.Timber;

public abstract class BaseApplication extends Application {

    @Override @CallSuper public void onCreate() {
        super.onCreate();
        // init LeakCanary
        if (!LeakCanary.isInAnalyzerProcess(this)) {
            LeakCanary.install(this);
        }
        // init Stetho
        Stetho.initializeWithDefaults(this);
        // init Log
        if (isApplicationDebuggable()) {
            // init Timber
            Timber.plant(new Timber.DebugTree());
            // init ARouter's log
            ARouter.openLog();
            ARouter.openInstantRun();
            ARouter.printStackTrace();
            // init AndroidDevMetrics
            AndroidDevMetrics.initWith(this);
        }
        // init ARouter
        ARouter.init(this);
    }

    /**
     * @Description: 判断APP是否可以debug
     * @Author: shentao@hsyuntai.com
     * @Date: 2017/3/6
     */
    protected abstract boolean isApplicationDebuggable();
}
